package org.reliablesource.jdt.viewers;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.reliablesource.jdt.linecounter.ReliableJDTPlugin;
import org.reliablesource.jdt.model.Contributor;
import org.reliablesource.jdt.model.ISourceElementInfo;
import org.reliablesource.jdt.model.JavaElementAdapter;

/**
 * 
 * ContributorLabelProvider.java<br>
 * Copyright (c) 2007, Reliable Source, Inc. All Rights Reserved<br>
 * <br>
 * 
 * Created on: May 12, 2007 <br>
 * <br>
 * 
 * @author Dennis Park 
 * 		<a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 * 
 * @since 1.0.0
 */
public class ContributorLabelProvider extends LabelProvider{

	@Override
	public String getText(Object element) {
		if (element instanceof JavaElementAdapter)
			return ((JavaElementAdapter) element).getName();
		if (element instanceof Contributor) 
			return ((Contributor) element).getName();
		else if(element instanceof ISourceElementInfo)
			return ((ISourceElementInfo)element).getName();
		return super.getText(element);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
	 */
	@Override
	public Image getImage(final Object _element) {
		if (_element != null) {

			if (_element instanceof JavaElementAdapter) {

				if (((JavaElementAdapter) _element).getAdaptedObject() instanceof IJavaProject)
					return ReliableJDTPlugin.getImageDescriptor(
							"icons/projects.gif").createImage();
				else
					return ReliableJDTPlugin.getImageDescriptor("icons/package_obj.gif").createImage();
			} else if (_element instanceof Contributor)
				return ReliableJDTPlugin.getImageDescriptor("icons/user-green-16x16.gif").createImage();
			else if (_element instanceof ISourceElementInfo) {
				if( (((ISourceElementInfo)_element).getJavaElement() instanceof ICompilationUnit)){
					return ReliableJDTPlugin.getImageDescriptor("icons/jcu_obj.gif").createImage();
				}
			}
		}

		return super.getImage(_element);
	}
}
